package org.example;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:何人亮
 * Date:2024-10-21
 * 20:26
 */
public class Test {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        String s=sc.nextLine();
        int n=sc.nextInt();
        String sn=sc.nextLine();
        while(n>0){
            String sss1=sc.nextLine();
            String[] sss=sss1.split(" ");
            String s1=sss[0];
            int a=Integer.parseInt(sss[1]);
            int b=Integer.parseInt(sss[2]);
            String p=new String();
            if(sss.length==4){
                p=sss[3];
            }
            if(s1.equals("print")){
                System.out.println(print(s,a, b));
                n--;
            }else if(s1.equals("reverse")){
                String s2=reverse(s,a,b);
                s=s2;
                n--;
            }else if(s1.equals("replace")){
                String s2=replace(s,a,b,p);
                s=s2;
                n--;
            }
        }
    }
    public static String print(String s,int a,int b){
        String ss1=new String();
        for (int i = a; i <=b ; i++) {
            Character c=s.charAt(i);
            ss1+=c.toString();
        }
        return ss1;
    }
    public  static String reverse(String s,int a,int b){
        String ss=new String();
        StringBuffer ss1=new StringBuffer();
        for (int i = 0; i < a; i++) {
            Character c=s.charAt(i);
            ss+=c.toString();
        }
        for (int i = a; i <=b ; i++) {
            Character c=s.charAt(i);
            ss1.append(c);
        }
        ss+=ss1.reverse().toString();
        for (int i = b+1; i <s.length() ; i++) {
            Character c=s.charAt(i);
            ss+=c.toString();
        }
        s=ss;
        return s;
    }
    public static String replace(String s,int a,int b,String p){
        String ss=new String();
        for (int i = 0; i < a; i++) {
            Character c=s.charAt(i);
            ss+=c.toString();
        }
        ss+=p;
        for (int i = b+1; i < s.length(); i++) {
            Character c=s.charAt(i);
            ss+=c.toString();
        }
        s=ss;
        return s;
    }
}
